#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;
const int D = 1e6 + 6;

int n, d;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> d;

  if (d == 0) {
    vector<int> a(n);
    for (int& x : a) cin >> x;
    sort(a.begin(), a.end());
    int num = unique(a.begin(), a.end()) - a.begin();
    cout << n - num;
    return 0;
  }
  int m = 1000000 / d;
  vector<vector<int>> a(d, vector<int>(m + 2, 0));
  rep(i, 1, n) {
    int x;
    cin >> x;
    int y = x / d;
    x = x % d;
    a[x][y]++;
  }
  int sum = 0;
  rep(i, 0, d - 1) {
    vector<int>& b = a[i];
    vector<int> dp0(m + 2, 0);
    vector<int> dp1(m + 2, 0);
    dp0[0] = b[0], dp1[0] = 0;
    rep(i, 1, m + 1) {
      dp0[i] = min(dp0[i - 1], dp1[i - 1]) + b[i];
      dp1[i] = dp0[i - 1];
    }
    sum += min(dp0[m], dp1[m]);
  }
  cout << sum;
  return 0;
}